/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: 北京银杉金服科技有限公司
 * 系统版本: 1.0.0
 * 开发人员: zhangfb
 * 开发时间: 2019/1/12 23:10
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.hyacinth.aurora.core.exception;

import com.hyacinth.aurora.constant.StatusEnum;

import java.io.Serializable;

/**
 * 封装异常类
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
public class AuroraException extends BaseException implements Serializable{

    private static final long serialVersionUID = 1L;

    public AuroraException(String errorCode, String errorMessage) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public AuroraException(Exception e, String errorCode, String errorMessage) {
        super(e, errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public AuroraException(String message) {
        super(message);
        this.errorMessage = message;
    }

    public AuroraException(String errorCode, String msgFormat, Object... args) {
        super(String.format(msgFormat, args));
        this.errorCode = errorCode;
    }

    public AuroraException(StatusEnum statusEnum, Object... args) {
        super(String.format(statusEnum.message(), args));
        this.errorCode = statusEnum.code();
    }

    public AuroraException(Exception oriEx) {
        super(oriEx);
    }

    public AuroraException(Throwable oriEx) {
        super(oriEx);
    }

    public AuroraException(String message, Exception oriEx) {
        super(message, oriEx);
        this.errorMessage = message;
    }

    public AuroraException(String message, Throwable oriEx) {
        super(message, oriEx);
        this.errorMessage = message;
    }


    public static boolean isResetByPeer(String msg) {
        if ("Connection reset by peer".equals(msg)) {
            return true;
        }
        return false;
    }
}
